$(function(){

    lay('#version').html('-v'+ laydate.v);
    laydate.render({
        elem: '#start_time'
    });
    laydate.render({
        elem: '#end_time'
    });
    $('.tests').on('click',function () {
        layer.open({
            id: 1,
            type: 1,
            title: '请输入提现金额',
            skin: 'layui-layer-rim',
            area: ['350px', 'auto'],
            content:  '<div style="margin-top: 20px;margin-left: 5px">' +
            '<p class="boxtop"><span class="txtitle">可提现余额</span><span class="rmb">￥</span>12312.00</p>' +
            '<p class="boxtop"><span class="txtitle">提现金额</span>￥<input type="test" class="txpwd" onkeydown="xzasdasd(this)"   ></p>' +
            '<p class="txtexts"></p>' +
            '<p class="boxtop"><span class="txtitle">服务费</span><span class="rmb fwf">￥</span></p>' +
            '<p class="txtexts">微信平台转账手续费率 0.1%</p>' +
            '</div>',
            btn: ['下一步', '取消'],
            btn1: function (index,layero) {
                layer.close(index)
                layer.open({
                    id: 2,
                    type: 1,
                    title: '提现银行卡信息',
                    skin: 'layui-layer-rim',
                    area: ['450px', 'auto'],
                    content:  '<div style="margin-top: 20px;margin-left: 5px">' +
                    '<p class="boxtop"><span class="txtitle">开户人姓名</span><input type="test" class="khr" onkeydown="xzasdasd(this)"></p>' +
                    '<p class="boxtop"><span class="txtitle">开户行</span>' +
                    '<select class="khh">' +
                    '<option value="0">请选择开户行</option>' +
                    '<option value="1002">工商银行</option>' +
                    '<option value="1005">农业银行</option>' +
                    '<option value="1026">中国银行</option>' +
                    '<option value="1003">建设银行</option>' +
                    '<option value="1001">招商银行</option>' +
                    '<option value="1066">邮储银行</option>' +
                    '<option value="1020">交通银行</option>' +
                    '<option value="1004">浦发银行</option>' +
                    '<option value="10006">民生银行</option>' +
                    '<option value="1009">兴业银行</option>' +
                    '<option value="1010">平安银行</option>' +
                    '<option value="1021">中信银行</option>' +
                    '<option value="1025">华夏银行</option>' +
                    '<option value="1027">广发银行</option>' +
                    '<option value="1022">光大银行</option>' +
                    '<option value="1032">北京银行</option>' +
                    '<option value="1056">宁波银行</option>' +
                    '</select>' +
                    '</p>' +
                    '<p class="boxtop"><span class="txtitle">转账银行卡</span><input type="test" class="zzyhk" onkeydown="xzasdasd(this)"   ></p>' +
                    '<p class="txtexts"></p>' +
                    '</div>',
                    btn: ['下一步', '取消'],
                    btn1: function (index, layero) {
                        layer.close(index)
                        layer.open({
                            id: 1,
                            type: 1,
                            title: '请输入提现金额',
                            skin: 'layui-layer-rim',
                            area: ['280px', 'auto'],
                            content: '<div style="margin-top: 20px;margin-left: 5px">' +
                            '<p class="boxtop"><span class="txtitle">\n' +
                            '取现流程需要进行短信确认，验证码已发送至管理员手机：139****6666，请按提示操作</span></p>' +
                            '<p class="boxtop"><input type="test" class="yzm" placeholder="请输入手机验证码" onkeydown="xzasdasd(this)"   > <input type="button" onclick="getchecknum()" value="获取验证码" class="getchecknum"></p>' +
                            '<p class="txtexts"></p>' +
                            '</div>',
                            btn: ['确认提现', '取消'],
                        })
                    }
                });
            }
        });
    });
    $('.weix').click(function () {
        
    })
    // $('.aaaa').on('click',function () {
    //     var orderid = $(this).attr('orderid');
    //     layer.msg('退款操作', {
    //         time: 0 //不自动关闭
    //         ,btn: ['继续发货', '退款','关闭']
    //         ,btn1: function(index){
    //             layer.open({
    //                 id:1,
    //                 type: 1,
    //                 title:'输入运单号',
    //                 skin:'layui-layer-rim',
    //                 area:['320px','auto'],
    //                 content: ' '
    //                 +'<input type="test" class="transport_two" style="width: 300px;margin-left: 5px;margin-top: 7px" placeholder="请输入运单号">'
    //                 ,
    //                 btn:['确认发货','取消'],
    //                 btn1: function (index,layero) {
    //                     var transport_two = $('.transport_two').val();
    //                     $.ajax({
    //                         'type':'POST',
    //                         'url':'/order/deliver-goods',
    //                         'data':{id:orderid,transport_two:transport_two},
    //                         'dataType':'json',
    //                         'success':function(data)
    //                         {
    //
    //                             if(data.code == 200){
    //                                 layer.msg(data.msg);
    //                                 setTimeout(function () {
    //                                     location.href = '/order/index';
    //                                 },1200);
    //                             } else {
    //                                 layer.msg(data.msg);
    //                                 setTimeout(function () {
    //                                     location.href = '/order/index';
    //                                 },1000);
    //                             }
    //
    //                         }
    //                     });
    //                 },
    //                 btn2:function (index,layero) {
    //                     layer.close(index);
    //                 }
    //             });
    //         }
    //         ,btn2:function(){
    //             layer.msg('是否确认退款', {
    //                 time: 0 //不自动关闭
    //                 ,btn: ['确认退款','关闭']
    //                 ,btn1:function () {
    //                     $.ajax({
    //                         'type':'POST',
    //                         'url':'/order/refund-goods',
    //                         'data':{
    //                             id:orderid,
    //                         },
    //                         'dataType':'json',
    //                         'success':function(data)
    //                         {
    //                             layer.msg(data.msg);
    //                             setTimeout(function () {
    //                                 location.href = '/order/index';
    //                             },1200);
    //                         }
    //                     });
    //                 }
    //             })
    //         }
    //     });
    // })
    //发货
    $('.send-goods').on('click',function () {
        ShowTransportNoBox();
        var id = $('.send-goods').attr('dataid');
        $('.b-confirm').on('click',function () {
            var transport_two = $('.transport_two').val();
            var express = $('.exp').val();
            $.ajax({
                'type':'POST',
                'url':'/order/send-goods',
                'data':{
                    id:id,
                    transport_two:transport_two,
                    express:express,
                },
                'dataType':'json',
                'success':function(data)
                {
                    if(data.code == 200){
                        layer.alert(data.msg);
                        setTimeout(function () {
                            location.href = '/order/index';
                        },1200);
                    } else {
                        layer.alert(data.msg);
                    }

                }
            });
        });

        $('.b-cancel').on('click',function () {
            $('.b-cancel').hide();
        })

    });

    function ShowTransportNoBox(){
        var exp = fahuo();
        var dIv=$("<div class='b-div'><h4 class='b-h4'>提示</h4>"+exp+"<div class='b-btn'><input type='button' value='确认' class='b-confirm btn-primary'><input type='button' value='取消' onclick='closeattr()' class='b-cancel'></div></div>");
        $("body").append(dIv);
    };

    //展示SKU
    $('.getsku').on('click',function(){
        // var googsid = $(this).attr('googsid');
        var goods_attr_id = $(this).attr('goods_attr_id');
        ajax("post","/order/get-googsattr",{attr_id:goods_attr_id},
            function success(data){

                var dIv="<div class='b-div'><h4 class='b-h4'>SKU</h4><div class='b-btn'>";
                dIv += "<table class=' table  table-striped table-bordered table-advance table-hover'>";
                dIv += '<tr>';
                dIv += '<th>属性</th>';
                dIv += '<th>原价</th>';
                dIv += '<th>折后价</th>';
                dIv += '<th>库存</th>';
                dIv += '</tr>';
                $(data.data).each(function ($key,$val) {
                    dIv += '<tr>';
                    dIv += '<td>'+$val.attr_value+'</td>';
                    dIv += '<td>'+$val.original_price+'</td>';
                    dIv += '<td>'+$val.discount_price+'</td>';
                    dIv += '<td>'+$val.inventory+'</td>';
                    dIv += '</tr>'
                })
                dIv+='</table>'
                dIv += "<input type='button' onclick='closeattr()' value='取消' class='b-cancel'></div></div>";
                $("body").append(dIv);
            }
        );

    });

    $('.refund').on('click',function () {
        var orderid = $(this).attr('orderid');
        layer.msg('退款操作', {
            time: 0 //不自动关闭
            ,btn: ['继续发货', '退款','关闭']
            ,btn1: function(index){
                layer.open({
                    id:1,
                    type: 1,
                    title:'输入运单号',
                    skin:'layui-layer-rim',
                    area:['400px','auto'],
                    content: fahuo() ,
                    btn:['确认发货','取消'],
                    btn1: function (index,layero) {
                        var transport_two = $('.transport_two').val();
                        var express = $('.exp').val();
                        $.ajax({
                            'type':'POST',
                            'url':'/order/deliver-goods',
                            'data':{id:orderid,transport_two:transport_two,express:express},
                            'dataType':'json',
                            'success':function(data)
                            {

                                if(data.code == 200){
                                    layer.msg(data.msg);
                                    setTimeout(function () {
                                        location.href = '/order/index';
                                    },1200);
                                } else {
                                    layer.msg(data.msg);

                                }

                            }
                        });
                    },
                    btn2:function (index,layero) {
                        layer.close(index);
                    }
                });
            }
            ,btn2:function(){
                layer.msg('是否确认退款', {
                    time: 0 //不自动关闭
                    ,btn: ['确认退款','关闭']
                    ,btn1:function () {
                        $.ajax({
                            'type':'POST',
                            'url':'/order/refund-goods',
                            'data':{
                                id:orderid,
                            },
                            'dataType':'json',
                            'success':function(data)
                            {
                                layer.msg(data.msg);
                                setTimeout(function () {
                                    location.href = '/order/index';
                                },1200);
                            }
                        });
                    }
                  })
            }
        });
    })


});

var exp =[
    '顺丰',
    '圆通',
    '申通',
    '中通',
    '百世汇通',
    '韵达',
    'EMS',
    '天天',
    '宅急送'
];
function fahuo() {
    var newexp = '<option value="">请选择快递公司</option>';
    $.each(exp,function (index,domEle){
        newexp += '<option value="'+domEle+'">'+domEle+'</option>'
    });
    return '<select class="exp" style="margin-left: 5px;margin-top: 7px;width:130px">'+newexp+'</select><input type="test" class="transport_two" style="width: 230px;margin-left: 5px;margin-top: 7px" placeholder="请输入运单号">'
}
function deliver() {
    // var orderid = $(this).attr('orderid');

    layer.msg('退款操作', {
        time: 0 //不自动关闭
        ,btn: ['继续发货', '退款','关闭']
        ,btn1: function(index){
            layer.open({
                id:1,
                type: 1,
                title:'输入运单号',
                skin:'layui-layer-rim',
                area:['320px','auto'],
                content: fahuo(),
                btn:['确认发货','取消'],
                btn1: function (index,layero) {
                    var transport_two = $('.transport_two').val();
                    var expval = $('.exp').val();

                    $.ajax({
                        'type':'POST',
                        'url':'/order/deliver-goods',
                        'data':{id:orderid,transport_two:transport_two,expval:expval},
                        'dataType':'json',
                        'success':function(data)
                        {


                        }
                    });
                },
                btn2:function (index,layero) {
                    layer.close(index);
                }
            });
        }
        ,btn2:function(){
            layer.msg('是否确认退款', {
                time: 0 //不自动关闭
                ,btn: ['确认退款','关闭']
                ,btn1:function () {
                    $.ajax({
                        'type':'POST',
                        'url':'/order/refund-goods',
                        'data':{
                            id:orderid,
                        },
                        'dataType':'json',
                        'success':function(data)
                        {
                            layer.msg(data.msg);
                            setTimeout(function () {
                                location.href = '/order/index';
                            },1200);
                        }
                    });
                }
            })
        }
    });
}
function xzasdasd($this) {
    var money = $($this).val();
    var fl = money*0.001;
    $('.fwf').html(fl.toFixed(2));
}
function closeattr() {
    $('.b-div').hide();
}



function getchecknum(){
    getCheckNum("18223600901",".getchecknum");
}
// 获取验证码
function getCheckNum(phoneNum,CheckNumBtn){
    var phone_num=phoneNum;
    if(/^[1][3,4,5,7,8][0-9]{9}$/.test(phone_num)){
        var second=90;
        var timer=setInterval(function(){
            second--;
            if(second!=0){
                $(CheckNumBtn).css({"background":"#999","color":"#eee"}).val("重新发送"+second+"s");
                $(CheckNumBtn).attr("disabled","disabled");
            }else{
                $(CheckNumBtn).val("获取验证码").css({"background":"#08c","color":"#fff"});
                $(CheckNumBtn).removeAttr("disabled");
                clearInterval(timer);
            }
        },1000);
        ajax("post","/code/send-code",{phone:phone_num},function success(data){
            if(data.code==200){
                layer.msg(data.msg);
            }else{layer.msg(data.msg);}
        });
    }else{
        layer.msg("您输入的电话有误，请重新输入")
    }
}